package com.example.binpacking.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.binpacking.model.QuestionnaireItem;
import com.example.binpacking.model.QuestionnaireOption;
import com.example.binpacking.model.Result;
import com.example.binpacking.model.dto.QuestionItemPageDto;
import com.example.binpacking.model.dto.QuestionNameItemOptionMDDto;
import com.example.binpacking.model.dto.QuestionOptionPageDto;
import com.example.binpacking.service.QuestionnaireItemService;
import com.example.binpacking.service.QuestionnaireOptionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/pelicanpsyc/api")
public class QuestionnaireOptionController {
    @Autowired
    private QuestionnaireOptionService questionnaireOptionService;
    @ApiOperation("分页并进行获得调查问卷条款选项")
    @PostMapping("/getQuestionnaireNameOption")
    public Result getQuestionnaireNameOption(@RequestBody QuestionOptionPageDto questionOptionPageDto) {
        Page<QuestionnaireOption> questionnaireOption = questionnaireOptionService.selectByDeletedAndItem(questionOptionPageDto.getItemid(),questionOptionPageDto.getIsdeleted(),questionOptionPageDto.getCurrentpage(),questionOptionPageDto.getPagesize());
        return Result.success(questionnaireOption);
    }
    @ApiOperation("插入调查问卷条框选项")
    @PostMapping("/insertQuestionnaireOption")
    public Result insertQuestionnaireOption(@RequestBody QuestionnaireOption questionnaireOption) {
        boolean isSuccess = questionnaireOptionService.save(questionnaireOption);
        if (isSuccess) {
            return Result.success(questionnaireOption);  // 返回传入的对象
        } else {
            return Result.fail("Failed to save questionnaire name.");
        }
    }
    @ApiOperation("修改调查问卷条款选项")
    @PostMapping ("/modifyQuestionnaireOption")
    public Result modifyQuestionnaireOption(@RequestBody QuestionNameItemOptionMDDto questionNameItemOptionMDDto) {
        int i =questionnaireOptionService.updateNameById(questionNameItemOptionMDDto.getId(),questionNameItemOptionMDDto.getName());
        if(i!=0){
            return Result.success("y");
        }else {
            return Result.fail("n");
        }
    }
    @ApiOperation("删除调查问卷条款选项(软删除)")
    @PostMapping ("/deleteQuestionnaireOption")
    public Result deleteQuestionnaireOption(@RequestBody QuestionNameItemOptionMDDto questionNameItemOptionMDDto) {
        int i =questionnaireOptionService.updateDeletedById(questionNameItemOptionMDDto.getId(),questionNameItemOptionMDDto.getIsdeleted());
        if(i!=0){
            return Result.success("y");
        }else {
            return Result.fail("n");
        }
    }
}
